﻿@using System.Web.Mvc.Html
@using Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Web.Security
@using GlobalResources
@model Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Web.Models.EditDeviceRuleModel

<div class="header_grid header_grid_general">
    <h3 class="grid_subheadhead_detail">@Strings.DeviceProperties</h3>
</div>

<section class="details_grid_general" id="deviceDetailsGrid">
    <h4 class="grid_subhead_detail_label">@Strings.DeviceId</h4>
    <p class="grid_detail_value" name="deviceField_deviceId">@Model.DeviceID</p>
</section>

<div class="header_grid header_grid_general">
    <h3 class="grid_subheadhead_detail">@Strings.RuleStatus</h3>
</div>

@{if (PermsChecker.HasPermission(Permission.EditRules))
{
    using (Ajax.BeginForm("UpdateRuleEnabledState", "DeviceRules", null,
    new AjaxOptions()
    {
        HttpMethod = "POST",
        OnBegin = "IoTApp.DeviceRuleProperties.onBegin",
        OnFailure = "IoTApp.DeviceRuleProperties.onFailure",
        OnSuccess = "IoTApp.DeviceRuleProperties.onSuccess",
        OnComplete = "IoTApp.DeviceRuleProperties.onComplete",
        LoadingElementId = "loadingElement"
    }, null))
    {

        @Html.AntiForgeryToken()
        @Html.HiddenFor(m => m.DeviceID)
        @Html.HiddenFor(m => m.DataField)
        @Html.HiddenFor(m => m.RuleId)
        @Html.HiddenFor(m => m.EnabledState, new { @Value = !Model.EnabledState })
    <section class="grid_rules_details" id="ruleStatusGrid">
        <div class="grid_rules_details__rule_status_container">
            @{if (Model.EnabledState)
            {
                <button type="submit" class="button_base rule_status_container___rule_status_button" id="rule_status_enabled">
                    @Strings.DisableRule
                </button>
            }
            else
            {
                <button type="submit" class="button_base rule_status_container___rule_status_button" id="rule_status_disabled">
                    @Strings.EnableRule
                </button>

                if (PermsChecker.HasPermission(Permission.DeleteRules))
                {
                    <button type="button" class="button_base rule_status_container___rule_status_button" id="remove_rule_button">
                        @Strings.RemoveRuleButtonLabel
                    </button>
                }
            }
}
        </div>
    </section>
    }
}
  else
  {
    <section class="details_grid_general" id="deviceDetailsGrid">
        <p class="grid_detail_value" name="ruleField_enabledState">
            @{if (Model.EnabledState)
            {
                @Strings.Enabled;
            }
            else
            {
                @Strings.Disabled;
            }
            }
        </p>
    </section>
}
}

<div class="header_grid header_grid_general">
    <h3 class="grid_subheadhead_detail">@Strings.RuleProperties</h3>
    @if (PermsChecker.HasPermission(Permission.EditRules))
    {
        @Html.ActionLink(@Strings.Edit, "EditRuleProperties", "DeviceRules",
            new { deviceId = Model.DeviceID, ruleId = Model.RuleId },
            new { id = "edit_metadata_link", @class = "link_grid_subheadhead_detail" })
    }
</div>

<section class="details_grid_general" id="rulePropertiesGrid">
    <h4 class="grid_subhead_detail_label">@Strings.DataFieldHeader</h4>
    <p class=" grid_detail_value" name="deviceField_@Model.DataField">@Model.DataField</p>

    <h4 class="grid_subhead_detail_label">@Strings.OperatorHeader</h4>
    <p class=" grid_detail_value" name="deviceField_@Model.Operator">@Model.Operator</p>

    <h4 class="grid_subhead_detail_label">@Strings.ThresholdHeader</h4>
    <p class=" grid_detail_value" name="deviceField_@Model.Threshold">@Model.Threshold</p>

    <h4 class="grid_subhead_detail_label">@Strings.RuleOutputHeader</h4>
    <p class=" grid_detail_value" name="deviceField_@Model.RuleOutput">@Model.RuleOutput</p>
</section>

